 //i,q区数值类型一样
 var valueTypes_IQ = [{
     value: 50,
     label: '8位的第00位'
 }, {
     value: 51,
     label: '8位的第01位'
 }, {
     value: 52,
     label: '8位的第02位'
 }, {
     value: 53,
     label: '8位的第03位'
 }, {
     value: 54,
     label: '8位的第04位'
 }, {
     value: 55,
     label: '8位的第05位'
 }, {
     value: 56,
     label: '8位的第06位'
 }, {
     value: 57,
     label: '8位的第07位'
 }];
 //m,v,db区数值类型一样
 var valueTypes_MV = [{
         value: 50,
         label: '8位的第00位'
     }, {
         value: 51,
         label: '8位的第01位'
     }, {
         value: 52,
         label: '8位的第02位'
     }, {
         value: 53,
         label: '8位的第03位'
     }, {
         value: 54,
         label: '8位的第04位'
     }, {
         value: 55,
         label: '8位的第05位'
     }, {
         value: 56,
         label: '8位的第06位'
     }, {
         value: 57,
         label: '8位的第07位'
     }, {
         value: 1,
         label: '8位有符号'
     }, {
         value: 2,
         label: '8位无符号'
     }, {
         value: 3,
         label: '16位有符号'
     }, {
         value: 4,
         label: '16位无符号'
     }, {
         value: 5,
         label: '32位有符号'
     }, {
         value: 6,
         label: '32位无符号'
     }, {
         value: 9,
         label: 'float'
     },

     {
         value: 11,
         label: 'SBCD8'
     }, {
         value: 12,
         label: 'BCD8'
     }, {
         value: 13,
         label: 'SBCD16'
     }, {
         value: 14,
         label: 'BCD16'
     }, {
         value: 15,
         label: 'SBCD32'
     }, {
         value: 16,
         label: 'BCD32'
     }
 ];
 //modBus的0区1区和两个三菱fx协议的X,Y,M三个区的数值类型只有布尔型
 var valueTypes_01 = [{
     value: 0,
     label: '布尔型'
 }];
 //modBus的3区4区数值类型
 var valueTypes_34 = [{
         value: 3,
         label: '16位有符号'
     }, {
         value: 4,
         label: '16位无符号'
     }, {
         value: 5,
         label: '32位有符号'
     }, {
         value: 6,
         label: '32位无符号'
     }, {
         value: 7,
         label: '64位有符号'
     }, {
         value: 8,
         label: '64位无符号'
     }, {
         value: 9,
         label: 'float'
     }, {
         value: 10,
         label: 'double'
     },

     {
         value: 13,
         label: 'SBCD16'
     }, {
         value: 14,
         label: 'BCD16'
     }, {
         value: 15,
         label: 'SBCD32'
     }, {
         value: 16,
         label: 'BCD32'
     }, {
         value: 17,
         label: 'SBCD64'
     }, {
         value: 18,
         label: 'BCD64'
     },
     //16位按位
     {
         value: 50,
         label: '16位的第00位'
     }, {
         value: 51,
         label: '16位的第01位'
     }, {
         value: 52,
         label: '16位的第02位'
     }, {
         value: 53,
         label: '16位的第03位'
     }, {
         value: 54,
         label: '16位的第04位'
     }, {
         value: 55,
         label: '16位的第05位'
     }, {
         value: 56,
         label: '16位的第06位'
     }, {
         value: 57,
         label: '16位的第07位'
     }, {
         value: 58,
         label: '16位的第08位'
     }, {
         value: 59,
         label: '16位的第09位'
     }, {
         value: 60,
         label: '16位的第10位'
     }, {
         value: 61,
         label: '16位的第11位'
     }, {
         value: 62,
         label: '16位的第12位'
     }, {
         value: 63,
         label: '16位的第13位'
     }, {
         value: 64,
         label: '16位的第14位'
     }, {
         value: 65,
         label: '16位的第15位'
     }
 ];
 //T645协议数值类型
 var valueTypes_T645 = [
	 {
		 value: 13,
		 label: 'SBCD16'
	 }, {
		 value: 14,
		 label: 'BCD16'
	 }, {
		 value: 15,
		 label: 'SBCD32'
	 }, {
		 value: 16,
		 label: 'BCD32'
	 }
 ];

 //两个三菱fx协议D区数值类型是一样的
 var valueTypes_Fx_D = [
	 {
         value: 3,
         label: '16位有符号'
     }, {
         value: 4,
         label: '16位无符号'
     }, {
         value: 5,
         label: '32位有符号'
     }, {
         value: 6,
         label: '32位无符号'
     },  {
         value: 9,
         label: 'float'
     }, {
         value: 13,
         label: 'SBCD16'
     }, {
         value: 14,
         label: 'BCD16'
     }, {
         value: 15,
         label: 'SBCD32'
     }, {
         value: 16,
         label: 'BCD32'
     }
 ];
 //高底限默认值算法函数；
 //valueType数值类型,magnification倍数,threshold阈值
 var defaultMinMax=function(valueType,magnification,threshold){
 	let type=Number(valueType);
 	let magn=Number(magnification);
 	let thre=Number(threshold);
	//value表示默认的最大值或最小值
 	let compute=function(value){
 		return value*magn+thre;
 	};
 	let defaultValue={
 		min:0,
 		max:65535
 	};
 	let minValue=0;
 	let maxValue=65535;
 	//8位按位和16位按位，还有布尔
 	if((50<=type<=65) || type===0){
 		minValue=-1;
 		maxValue=2;
 	//64位高底限都为0；
 	}else if([7,8,17,18].includes(type)){
 		minValue=0;
 		maxValue=0;
 	}
 	switch (type) {
 		case 1:     //8位有符号和sbcd8
 		case 11:
 		   minValue=compute(-79);
 		   maxValue=compute(79);
 		   break;
 		case 2:      //8位无符号和bcd8
 		case 12:
 		   minValue=thre;
 		   maxValue=compute(80);
 		   break;
 		case 3:     //16位有符号
 		   minValue=compute(-32768);
 		   maxValue=compute(32767);
 		   break;
 		case 4:     //16位无符号
 		   minValue=thre;
 		   maxValue=compute(65535);
 		   break;
 		case 5:     //32位有符号
 		   minValue=compute(-2147483648);
 		   maxValue=compute(2147483647);
 		   break;
 		case 6:     //32位无符号
 		   minValue=thre;
 		   maxValue=compute(4294967296);
 		   break;
 		case 9:     //float
 		   minValue=compute(-100000);
 		   maxValue=compute(100000);
 		   break;
 		case 10:     //double
 		   minValue=compute(-100000);
 		   maxValue=compute(100000);
 		   break;
 		case 13:     //sbcd16
 		   minValue=compute(-7999);
 		   maxValue=compute(7999);
 		   break;
 		case 14:     //bcd16
 		   minValue=thre;
 		   maxValue=compute(8000);
 		   break;
 		case 15:     //sbcd32
 		   minValue=compute(-79999);
 		   maxValue=compute(79999);
 		   break;
 		case 16:     //bcd32
 		   minValue=thre;
 		   maxValue=compute(80000);
 		   break;
 	}
    defaultValue.min = minValue;
    defaultValue.max = maxValue;
    return defaultValue;

 };

 function  numToTime(num){
 	 let newNum=Number(num) || 0;
 	 switch(newNum){
 		case 0:
 		   return "00:00:00";
 		case 1:
 		   return "01:00:00";
 	    case 2:
 	       return "02:00:00";
 		case 3:
 		   return "03:00:00";
 		case 4:
 		   return "04:00:00";
 		case 5:
 		   return  "05:00:00";
 		case 6:
 		   return "06:00:00";
 		case 7:
 		   return "07:00:00";
 		case 8:
 		   return "08:00:00";
 		case 9:
 		   return "09:00:00";
 		case 10:
 		   return "10:00:00";
 		case 11:
 		   return "11:00:00";
 		case 12:
 		   return "12:00:00";
 		case 13:
 		   return "13:00:00";
 		case 14:
 		   return "14:00:00";
 		case 15:
 		   return "15:00:00";
 		case 16:
 		   return "16:00:00";
 		case 17:
 		   return "17:00:00";
 		case 18:
 		   return "18:00:00";
 		case 19:
 		   return "19:00:00";
 		case 20:
 		   return "20:00:00";
 		case 21:
 		   return "21:00:00";
 		case 22:
 		   return "22:00:00";
 		case 23:
 		   return "23:00:00";
 	}
 };

 var reportTypes = [{
     value: 0,
     label: '设备实时数据(0)'
 }, {
     value: 1,
     label: '设备参数数据(1)'
 }, {
     value: 10,
     label: '厂商实时数据(10)'
 }, {
     value: 11,
     label: '厂商参数数据(11)'
 }];


 var reportTypes_54 = [{
     value: 0,
     label: '设备实时数据(0)'
 }, {
     value: 1,
     label: '设备参数数据(1)'
 }, {
     value: 10,
     label: '厂商实时数据(10)'
 }, {
     value: 11,
     label: '厂商参数数据(11)'
 },{
     value: 3,
     label: '中间变量'
 },{
     value: 4,
     label: '只写数据'
 }




 ];

 var saves = [{
     value: 1,
     label: '存储'
 }, {
     value: 2,
     label: '不存储'
 }, {
     value: 3,
     label: '变化存储'
 }];

 var options = [{
         value: 1,
         label: '只读数值'
     }, {
         value: 2,
         label: '读写数值'
     }, {
         value: 3,
         label: '只读开关'
     }, {
         value: 4,
         label: '读写开关'
     }, {
         value: 5,
         label: '只读状态(红/绿)'
     }, {
         value: 15,
         label: '只读状态(暗/绿)'
     }, {
         value: 6,
         label: '读写状态'
     }, {
         value: 7,
         label: '只读报警(1闪)'
     }, {
         value: 13,
         label: '只读报警(0闪)'
     }, {
         value: 8,
         label: '读写报警'
     }
     // {
     // 	value: 5,
     // 	label: '字符串'
     // },
     // {
     // 	value: 6,
     // 	label: '多位开关'
     // }
 ];
 //三菱协议X区只有只读类型
 var optionsOnlyRead = [{
         value: 1,
         label: '只读数值'
     },  {
         value: 3,
         label: '只读开关'
     },  {
         value: 5,
         label: '只读状态(红/绿)'
     }, {
         value: 15,
         label: '只读状态(暗/绿)'
     },  {
         value: 7,
         label: '只读报警(1闪)'
     }, {
         value: 13,
         label: '只读报警(0闪)'
     }
     // {
     // 	value: 5,
     // 	label: '字符串'
     // },
     // {
     // 	value: 6,
     // 	label: '多位开关'
     // }
 ];

 var points = [{
     value: 0,
     label: 0
 }, {
     value: 1,
     label: 1
 }, {
     value: 2,
     label: 2
 }, {
     value: 3,
     label: 3
 }, {
     value: 4,
     label: 4
 },
 {
     value: 5,
     label: 5
 },
 {
     value: 6,
     label: 6
 },
 {
     value: 7,
     label: 7
 },
 {
     value: 8,
     label: 8
 }
 ];
//rs485,rs232,lora,zigbee四种端口对应的协议是一样的；
 var protocols_485 = [
	 {
         value: 'modbus_rtu_master',
         label: 'Modbus RTU Master',
     },
	 {
	     value: 'modbus_ascii',
	     label: 'Modbus Ascii',
	 },
     // {
     // 	value: 'modbus_rtu_slave',
     // 	label: 'Modbus RTU Slave',
     // },
     {
         value: 's7_200_ppi',
         label: 'S7-200 PPI',
     },
	 {
	     value: 'mitsubishi_fx_program',
	     label: 'Mitsubishi_Fx_Program',//三菱Fx系列编程口
	 },
	 {
	     value: 'mitsubishi_fx_serial',
	     label: 'Mitsubishi_Fx_Serial',//三菱Fx系列串口
	 },
	 {
	     value: 'dl_t645_1997',
	     label: 'DL/T645-1997',
	 },
	 {
	     value: 'dl_t645_2007',
	     label: 'DL/T645-2007',
	 }
 ];
 var protocols_ethernet = [{
     value: 'modbus_tcp_client',
     label: 'Modbus TCP Client',
 },
 {
 	value: 'modbus_rtu_over_tcp',
 	label: 'Modbus RTU Over TCP',
 },
 {
     value: 's7_200_smart',
     label: 'S7-200 Smart',
 }, {
     value: 's7_200',
     label: 'S7-200',
 },
 {
     value: 's7_300_400',
     label: 'S7-300/400',
 },
 {
     value: 's7_1200',
     label: 'S7-1200',
 }, {
     value: 's7_1500',
     label: 'S7-1500',
 }];
 var protocols_local = [{
     value: 'modbus',
     label: 'Modbus',
 }];
 var channels = [
	 {
         value: 'rs485_0',
         label: 'RS485_0'
     },

     // {
     //   value:'rs485_1',
     //   label:'RS485_1'
     // },
     // {
     //   value:'rs485_2',
     //   label:'RS485_2'
     // },
     {
         value: 'rs232_0',
         label: 'RS232_0'
     },
	   {
         value: 'ethernet_0',
         label: 'Ethernet_0'
     }, {
         value: 'zigbee_0',
         label: 'Zigbee_0'
     }, {
         value: 'lora_0',
         label: 'LoRa_0'
     }, {
         value: 'local',
         label: 'Local(内部变量)'
     }
 ];
 //com1', 'com2', 'com3', 'com4', 'com5', 'com6', 'com7', 'com8', 'lora1', 'lora2', 'zigbee1', 'zigbee2', 'ethernet1', 'ethernet2'
 //设备为5.3版本的设备通道
 var  channels_53=[
   {
        value: 'ethernet1',
        label: 'Ethernet1'
    },
    {
     	      value: 'ethernet2',
     	      label: 'Ethernet2'
     },
	{
	 	  value: 'com1',
	 	  label: 'COM1'
	 },
	 {
	 	  value: 'com2',
	 	  label: 'COM2'
	 },
	 {
	 	  value: 'com3',
	 	  label: 'COM3'
	 },
	 {
	 	  value: 'com4',
	 	  label: 'COM4'
	 },
	 {
	 	  value: 'com5',
	 	  label: 'COM5'
	 },
	 {
	 	  value: 'com6',
	 	  label: 'COM6'
	 },
	 {
	 	  value: 'com7',
	 	  label: 'COM7'
	 },
	 {
	 	  value: 'com8',
	 	  label: 'COM8'
	 },


	  {
	      value: 'zigbee1',
	      label: 'Zigbee1'
	  },
	   {
		   value: 'zigbee2',
		   label: 'Zigbee2'
	   },

	  {
	      value: 'lora1',
	      label: 'LoRa1'
	  },
	  {
	      value: 'lora2',
	      label: 'LoRa2'
	  },

	  {
	      value: 'local',
	      label: 'Local(内部变量)'
	  }


 ];

 var baudRates = [{
     value: 1200,
     label: 1200
 }, {
     value: 2400,
     label: 2400
 }, {
     value: 4800,
     label: 4800
 }, {
     value: 9600,
     label: 9600
 }, {
     value: 19200,
     label: 19200
 }, {
     value: 38400,
     label: 38400
 }, {
     value: 57600,
     label: 57600
 }, {
     value: 115200,
     label: 115200
 }];

 var parities = [{
     value: 0,
     label: "None"
 }, {
     value: 1,
     label: "Odd"
 }, {
     value: 2,
     label: "Even"
 }];
 var speeds = [{
     value: 300,
     label: "300"
 }, {
     value: 1200,
     label: "1200"
 }, {
     value: 2400,
     label: "2400"
 }, {
     value: 4800,
     label: "4800"
 }, {
     value: 9600,
     label: "9600"
 }, {
     value: 19200,
     label: "19200"
 }, {
     value: 38400,
     label: "38400"
 }, {
     value: 62500,
     label: "62500"
 }];
 var whileIfs = [{
     value: 1,
     label: '等于A'
 }, {
     value: 2,
     label: '小于A'
 }, {
     value: 3,
     label: '大于A'
 }, {
     value: 4,
     label: '大于A并且小于B'
 }, {
     value: 5,
     label: '小于A或者大于B'
 }, {
     value: 6,
     label: '开关开'
 }, {
     value: 7,
     label: '开关关'
 }];
 //通道参数
 var rs485Config = {
     baud_rate: 9600, // 波特率为 9600
     data_bits: 8, // 数据位为 8
     stop_bits: 1, // 停止位为 1
     parity: 0
 };

 var comConfig = {
     baud_rate: 9600, // 波特率为 9600
     data_bits: 8, // 数据位为 8
     stop_bits: 1, // 停止位为 1
     parity: 0,
	   timeout:0
 };
 var ethernetConfig = {
     dhcp: 0, // 是否自动获取IP
     local_ip: "192.168.0.2", // 本地IP
     //local_port: 502, //本地端口
     subnet_mask: '255.255.255.0', //本地子网掩码
     gateway: '192.168.0.1',// 默认网关
     dns:'114.114.114.114',
     dns2:'8.8.8.8',
     ntp:'ntp.ntsc.ac.cn'

 };
 var loraConfig = {
     channel: 0, // 通讯端口
     address: 0, //模块地址
     air_rate: 2400 ,// 空中速率 单位 bps
	   timeout:0,
     data_encrypt:0,
     net_id:''
 };
 var zigbeeConfig = {
     channel: 20, // 通讯端口
     pan_id: 10753, //PAN ID
     timeout:0

 };
 var localConfig = {
     di_count: 0,
     do_count: 0,
     ai_count: 0,
     ao_count: 0,
     temp_count: 0,
     pi_count: 0
 };

 var timeoutOptions=[
	{
	    value:0,
		label:'自动'
    },
	{
	   value:20,
	   label:20
	},
	{
	   value:30,
	   label:30
	},
	{
	    value:50,
	    label:50
	},
	{
	    value:100,
	    label:100
	}
 ];

 //以下为不同协议的子设备参数
 //modbus_master
 var modbusMaster = {
     poll_cycle: 0, // 设备轮询周期，单位 S
     poll_interval: 20, // 轮询指令间隔，单位 mS
     response_timeout: 1000, // 通讯超时时长，单位 mS
     write16_cmd: 0, // 4区16位写功能选择
     int16_order: 0, // 16位整数解码顺序
     int32_order: 0, // 32位整数解码顺序
     float_order: 0, // 32位浮点数解码顺序
     int64_order: 0, // 64位整数解码顺序
     double_order: 0, // 64位浮点数解码顺序
     crc_mode: 0, // CRC检验方式[高字节，低字节]/[低字节，高字节]
     max_length: 120 ,// 最大采集长度
     framing_interval:32, //非连续地址间隔 ，数值
     ascii_order:0,         //ASCII排序0: AB 1: BA
	   state_reg: {
	     push_interval: 60,            // 上报频率 s
	     ping_enable: 0,               // 心跳使能
	     ping_address:"4x00101",              // 心跳地址
	     state_enable: 0,              // 状态使能
	     state_address: "4x00102"             // 状态地址
	 }
 };
 var modbusClient = {
     work_mode:0,
     server_ip: "192.168.0.2", // 远程IP
     server_port: 502,
     poll_cycle: 0, // 设备轮询周期，单位 S
     poll_interval: 20, // 轮询指令间隔，单位 mS
     response_timeout: 1000, // 通讯超时时长，单位 mS
     write16_cmd: 0, // 4区16位写功能选择
     int16_order: 0, // 16位整数解码顺序
     int32_order: 0, // 32位整数解码顺序
     float_order: 0, // 32位浮点数解码顺序
     int64_order: 0, // 64位整数解码顺序
     double_order: 0, // 64位浮点数解码顺序
     //crc_mode: 0, // CRC检验方式[高字节，低字节]/[低字节，高字节]
     max_length: 120,
     framing_interval:32, //非连续地址间隔 ，数值
     ascii_order:0,         //ASCII排序0: AB 1: BA
	   state_reg: {
	     push_interval: 60,            // 上报频率 s
	     ping_enable: 0,               // 心跳使能
	     ping_address:"4x00101",              // 心跳地址
	     state_enable: 0,              // 状态使能
	     state_address: "4x00102"             // 状态地址
	 }
 };
 var modbusSlave = {
     int16_order: 0, // 16位整数解码顺序
     int32_order: 0, // 32位整数解码顺序
     float_order: 0, // 32位浮点数解码顺序
     int64_order: 0, // 64位整数解码顺序
     double_order: 0, // 64位浮点数解码顺序
     response_delay: 10 ,//响应延时时间
     framing_interval:32, //非连续地址间隔 ，数值
     ascii_order:0,         //ASCII排序0: AB 1: BA
	   state_reg: {
	     push_interval: 60,            // 上报频率 s
	     ping_enable: 0,               // 心跳使能
	     ping_address:"4x00101",              // 心跳地址
	     state_enable: 0,              // 状态使能
	     state_address: "4x00102"             // 状态地址
	 }
 };
 //v5.3下local端口，子设备参数
 var localSlave= {
     com1: 0,
     com2: 0,
     com3: 0,
     com4: 0,
     com5: 0,
     com6: 0,
     com7: 0,
     com8: 0,
     ethernet1: 0,
     ethernet2: 0,
     zigbee1: 0,
     zigbee2: 0,
     response_delay: 10 ,//响应延时时间
     data_map:0,          //数据映射，默认关闭
     //framing_interval:32, //非连续地址间隔 ，数值
    // ascii_order:0,         //ASCII排序0: AB 1: BA
 	 state_reg: {
 	     push_interval: 60,            // 上报频率 s
 	     ping_enable: 0,               // 心跳使能
 	     ping_address:"4x00101",              // 心跳地址
 	     state_enable: 0,              // 状态使能
 	     state_address: "4x00101"             // 状态地址
 	 }
 };
 //v5.4下local端口，子设备参数
 var localSlave54 = {
     // ethernet_0: 0,
     // rs485_0: 0,
     // rs485_1: 0,
     // rs485_2: 0,
     // rs485_1: 0,
     // rs232_0: 0,
     response_delay: 10 ,//响应延时时间
     data_map:0,          //数据映射，默认关闭
     //framing_interval:32, //非连续地址间隔 ，数值
    // ascii_order:0,         //ASCII排序0: AB 1: BA
	 // state_reg: {
	 //     push_interval: 60,            // 上报频率 s
	 //     ping_enable: 0,               // 心跳使能
	 //     ping_address:"4x00101",              // 心跳地址
	 //     state_enable: 0,              // 状态使能
	 //     state_address: "4x00101"             // 状态地址
	 // }
 };




 //s7_200_ppi和三菱fx编程口协议配置参数一样
 var s7_200_ppi = {
	 plc_type:0,
     poll_cycle: 0, // 设备轮询周期，单位 S
     poll_interval: 20, // 轮询指令间隔，单位 mS
     response_timeout: 1000, // 通讯超时时长，单位 mS
	 state_reg: {
	     push_interval: 60,            // 上报频率 s
	     ping_enable: 0,               // 心跳使能
	     ping_address:"VW0",           // 心跳地址
	     state_enable: 0,              // 状态使能
	     state_address: "VW2"          // 状态地址
	 }
 };

 var dl_T645 = {
	 poll_cycle: 0, // 设备轮询周期，单位 S
	 poll_interval: 20, // 轮询指令间隔，单位 mS
	 response_timeout: 1000 // 通讯超时时长，单位 mS
 };

//s7_200_smart，s7-1200,s7-1500协议配置参数相同
 var s7_1200_1500 = {
     work_mode:0,
     server_ip: "192.168.2.1", // 远程IP
     server_port: 102,
     poll_cycle: 0, // 设备轮询周期，单位 S
     poll_interval: 20, // 轮询指令间隔，单位 mS
     response_timeout: 1000, // 通讯超时时长，单位 mS
     rack_num: 0, // 机架号[Rack]
     slot_num: 2, // 槽号[Slot],默认2
	 state_reg: {
	     push_interval: 60,            // 上报频率 s
	     ping_enable: 0,               // 心跳使能
	     ping_address:"DB1.DB0.0",              // 心跳地址
	     state_enable: 0,              // 状态使能
	     state_address: "DB1.DB0.1"             // 状态地址
	 }
 };

 //三菱fx协议下PLC类型
 var protocols_PLC =[
 	 {
 		 value:0,
 		 label:'Fx3'
 	 },
 	 {
 	 	value:1,
 	 	label:'Fx2/1'
 	 }
 ];

 //三菱fx系列串口协议配置参数
 var fx_serial_port={
	 protocol_format:1,     //协议格式
	 plc_type:0,             //plc类型
	 poll_cycle: 0, // 设备轮询周期，单位 S
	 poll_interval: 20, // 轮询指令间隔，单位 mS
	 response_timeout: 1000, // 通讯超时时长，单位 mS
	 is_check:0,             //是否效验
	 state_reg: {
	     push_interval: 60,            // 上报频率 s
	     ping_enable: 0,               // 心跳使能
	     ping_address:"D0000",              // 心跳地址
	     state_enable: 0,              // 状态使能
	     state_address: "D0001"             // 状态地址
	 }

 };
 var cmds_16 = [{
     value: 0,
     label: '0x06'
 }, {
     value: 1,
     label: '0x10'
 }];
 var orders_16 = [{
     value: 0,
     label: 'AB'
 }, {
     value: 1,
     label: 'BA'
 }];
 var orders_32 = [{
     value: 0,
     label: 'ABCD'
 }, {
     value: 1,
     label: 'CDAB'
 }, {
     value: 2,
     label: 'BADC'
 }, {
     value: 3,
     label: 'DCBA'
 }];
 var orders_64 = [{
     value: 0,
     label: 'ABCDEFGH'
 }, {
     value: 1,
     label: 'GHEFCDAB'
 }, {
     value: 2,
     label: 'BADCFEHG'
 }, {
     value: 3,
     label: 'KGFEDCBA'
 }];
 var crc_modes = [{
     value: 0,
     label: 'LH'
 }, {
     value: 1,
     label: 'HL'
 }];

var waterMarks = [
	 {
	 	value:0,
	 	label:'瞬时流量'
	 },
	 {
	 	value:1,
	 	label:'累计流量'
	 },
	 {
	 	value:10,
	 	label:'水位'
	 },
	 {
	 	value:20,
	 	label:'室温'
	 },
	 {
	 	value:30,
	 	label:'水压'
	 },
	 {
	 	value:40,
	 	label:'水温'
	 },

	 {
	 	value:51,
	 	label:'水质水温'
	 },
	 {
	 	value:52,
	 	label:'PH值'
	 },
	 {
	 	value:53,
	 	label:'溶解氧'
	 },
	 {
	 	value:54,
	 	label:'电导率'
	 },
	 {
	 	value:55,
	 	label:'浊度'
	 },
	 {
	 	value:56,
	 	label:'叶绿素'
	 },
	 {
	 	value:57,
	 	label:'蓝绿素'
	 }
];


//modbus系列数据通道是一样的；
 var addSensor_modbus = [{
         value: '0',
         label: '0区(0x继电器状态)'
     }, {
         value: '1',
         label: '1区(1x输入状态)'
     }, {
         value: '3',
         label: '3区(3x输入寄存器)'
     }, {
         value: '4',
         label: '4区(4x保持寄存器)'
     }

 ];
 //s7_200_smart和s7_200_ppi数据通道是一样的；
 var addSensor_s7200 = [{
         value: "I",
         label: 'I'
     }, {
         value: 'Q',
         label: 'Q'
     }, {
         value: 'M',
         label: 'M'
     }, {
         value: 'V',
         label: 'V'
     }

 ];
 //s7_1200和s7_1500数据通道是一样的；
 var addSensor_1200_1500 = [{
     value: 'I',
     label: 'I'
 }, {
     value: 'Q',
     label: 'Q'
 }, {
     value: 'M',
     label: 'M'
 }, {
     value: 'D',
     label: 'DB'
 }];

 //两个三菱fx数据通道是一样的；
 var addSensor_mitsubishi_fx = [{
     value: 'X',
     label: 'X'
 }, {
     value: 'Y',
     label: 'Y'
 }, {                   //X,Y为八进制，M,D为十进制
     value: 'M',
     label: 'M'
 }, {
     value: 'D',
     label: 'D'
 }];

 //三菱fx协议参数协议格式选项
 var famtterFxs=[
	 {
	     value: 0,
	     label: 1
	 }, {
	     value: 1,
	     label: 4
	 }
 ];

 //三菱fx协议参数是否效验选项
 var checkFxs=[
 	 {
 	     value: 0,
 	     label: '否'
 	 }, {
 	     value: 1,
 	     label: '是'
 	 }
 ];

 //v1网关和直连设备的相关数据
 var oldOptions = [
	 {
         value: 1,
         label: '数值'
     },
	 {
         value: 2,
         label: '开关'
     },
     {
         value: 3,
         label: '状态(红/绿)'
     },
     {
         value: 8,
         label: '状态(暗/绿)'
     },
     {
         value: 4,
         label: '报警(1闪)'
     },
     {
         value: 7,
         label: '报警(0闪)'
     },

     // {
     // 	value: 5,
     // 	label: '字符串'
     // },
     {
         value: 6,
         label: '多位开关(已停用)'
     }
 ];

 var oldPoints = [{
         value: 0,
         label: '无小数位'
     },
     {
         value: 1,
         label: '1位小数'
     },
     {
         value: 2,
         label: '2位小数'
     },
     {
         value: 3,
         label: '3位小数'
     },
     {
         value: 4,
         label: '4位小数'
     }
 ];

 var steps = [{
         value: 1,
         label: 1
     },
     {
         value: 2,
         label: 2
     },
     {
         value: 3,
         label: 3
     },
     {
         value: 4,
         label: 4
     }
 ];

 //固件版本号转浮点数，用于添加子设备时，判断是否显示状态寄存器配置；
 var versionToFloat = function(version){
 	if(!version){return 0};
 	let newVersion=(version.startsWith('V') || version.startsWith('v'))?version.substr(1):version;
 	let arr=newVersion.split('.');
 	if(arr.length==1){
 		return Number(arr[0]);
 	}else if(arr.length==2){
        return Number(arr[0]+'.'+arr[1][0]);
 	}else{
 		return Number(arr[0]+'.'+arr[1][0]+arr[2][0]);
 	}
 };

 //v5设备配置或模板地址批量方法
 var padLeft = function(str, len, char) {
	 var isStr=str.toString();
     let strlen = isStr.length;
	 let newStr = '';
     if (strlen < len) {
         for (let i = 0; i < len - strlen; i++) {
             newStr = newStr + char;
         }
         newStr = newStr + isStr;
     } else if(strlen > len){
         newStr=isStr.substr(isStr.length-len);
     }else{
		 newStr = isStr;
	 }
     return newStr;
 };

 //批量生成地址函数
 //createDataKey(基础地址，数值类型，新增数量,是否包含基础地址)
 var createDataKey = function(dataKey, valueType, count,hasFirst=true) {
     //console.log(dataKey, valueType, count);
     //获取首字母地址前缀
     let step = 1;
     let dataChannel = dataKey[0];
     let prefixLength = 0;
     let protocolType = 'modbus';
     let pointIndex = 0;
	 //三菱fx协议对应地址规则专用正则
	 let reg=/^[XYMD][0-9]{4,5}$/;
	 if(!reg.test(dataKey)){
		 switch (dataChannel) {
			 case '0':
			 case '1':
			 case '3':
			 case '4':
				 prefixLength = 2;
				 protocolType = 'modbus';
				 break;
			 case 'I':
			 case 'Q':
			 case 'M':
			 case 'V':
				 protocolType = 'siemens';
				 prefixLength = isNaN(dataKey[1]) ? 2 : 1;
				 break;
			 case 'A':
				 protocolType = 'siemens';
				 prefixLength = isNaN(dataKey[2]) ? 3 : 2;
				 break;
			 case 'D':
				 pointIndex = dataKey.indexOf('.');
				 protocolType = 'siemens';
				 prefixLength = isNaN(dataKey[pointIndex + 3]) ? pointIndex + 4 : pointIndex + 3;
				 break;
			 default:
				 return '地址格式错误';
		 }
		 let prefix = dataKey.substr(0, prefixLength);
		 let address = dataKey.substr(prefixLength);
		 //根据协议枚举数据点增量（按位的需单独获取最大类型、最大小数位、整数部分、小数部分）
		 let dataInt, decimal, maxDecimal, maxType = 0;
		 if (protocolType == 'modbus') {
			 if (valueType >= 50) {
				 step = 0.1;
				 maxType = 65;
				 maxDecimal = 15;
				 decimal = address * 100 % 100;
				 dataInt = Math.floor(address);
			 } else if ([0, 3, 4, 13, 14].indexOf(valueType) >= 0) {
				 step = 1;
			 } else if ([5, 6, 9, 15, 16].indexOf(valueType) >= 0) {
				 step = 2;
			 } else if ([7, 8, 10, 17, 18].indexOf(valueType) >= 0) {
				 step = 4;
			 } else {
				 return '数值类型不允许';
			 }
		 } else {
			 if (valueType >= 50) {
				 step = 0.1;
				 maxType = 57;
				 maxDecimal = 7;
				 dataInt = Math.floor(address);
				 decimal = address * 10 % 10;
			 } else if ([1, 2, 11, 12].indexOf(valueType) >= 0) {
				 step = 1;
			 } else if ([3, 4, 13, 14].indexOf(valueType) >= 0) {
				 step = 2;
			 } else if ([5, 6, 9, 15, 16].indexOf(valueType) >= 0) {
				 step = 4;
			 } else if ([17, 18].indexOf(valueType) >= 0) {
				 step = 8;
			 } else {
				 return '数值类型不允许';
			 }
		 }
		 //生成地址（modbus长度不够时需补位）
		 var result=[];
		 var newCount=count;
		 if(hasFirst){
			 result = [{
				 value_type: valueType,
				 data_key: dataKey
			 }];
			 newCount=count-1;
		 }
		 let addressInt = '';
		 let addressDecimal = 0;
		 for (let i = 0; i < newCount; i++) {
			 if (step < 1) {
				 if (++decimal > maxDecimal) {
					 decimal = 0;
					 dataInt++;
				 }
				 if (++valueType > maxType) {
					 valueType = 50;

				 }

				 if (protocolType == 'modbus') {
					 addressInt = padLeft(dataInt, 5, '0');
					 addressDecimal = padLeft(decimal, 2, '0');
				 } else {
					 addressInt = dataInt;
					 addressDecimal = decimal;
				 }

				 address = addressInt + '.' + addressDecimal;
			 } else {
				 address = Number(address) + step;
				 if (protocolType == 'modbus') {
					 address = padLeft(address, 5, '0');
				 }
			 }
			 result.push({
				 value_type: valueType,
				 data_key: prefix + address
			 })
		 }
	}else{
		let prefix=dataChannel;
		let address = dataKey.substr(1);
		switch (dataChannel) {
			case 'X':
			case 'Y':
			case 'M':
			    step=1;
				break;
			case 'D':
				if ([3, 4, 13, 14].indexOf(valueType) >= 0) {
					step = 1;
				}else if([5, 6, 9, 15, 16].indexOf(valueType) >= 0) {
					step = 2;
				}
				break;
			default:
				return '地址格式错误';
		}
		var result=[];
		var newCount=count;
		if(hasFirst){
			result = [{
				value_type: valueType,
				data_key: dataKey
			}];
			newCount=count-1;
		}
		for (let i = 0; i < newCount; i++) {
			if(dataChannel=='X' || dataChannel=='Y'){
			   address = Number(address) + step;
			   address = padLeft(address, 4, '0');
               var add3=Number(address[3])>7?'0':address[3];
			   var add2=Number(address[3])>7?Number(address[2])+1:address[2];
			   //var add2=Number(address[2])>9?'0':address[2];
			   //var add1=Number(address[1])>9?'0':address[1];
			   //var add0=Number(address[0])>9?'0':address[0];
			   //if(Number(address[3])>7){add2=(Number(address[2])+1).toString();}
			   //if(Number(address[2])>9){add1=(Number(address[1])+1).toString();}
			   //if(Number(address[1])>9){add0=(Number(address[0])+1).toString();}
			   address = address[0]+address[1]+add2+add3;
			   if(address.length>4){
				   address=address.substr(address.length-4);
			   }
			   //console.log(address);
			}else{
				//三菱D区可五位，最小D10000，没有D00000
				if(Number(address)<=9999){
				   address = Number(address) + step;
				   address = padLeft(address, 4, '0');
			    }else if(dataChannel=='D' && Number(address)>9999 && Number(address)<99998){
				   address = Number(address) + step;
				   //address = padLeft(address, 5, '0');
				}
			}
			result.push({
				value_type: valueType,
				data_key: prefix + address
			})
		}
	}
     //console.log(result);
     return result;
	};


 var configData = {
     valueTypes_IQ,
     valueTypes_MV,
     valueTypes_01,
     valueTypes_34,
	 valueTypes_T645,
	 valueTypes_Fx_D,
     reportTypes,
     reportTypes_54,
     saves,
     options,
	 optionsOnlyRead,
     points,
     protocols_485,
	 protocols_PLC,
     protocols_ethernet,
     protocols_local,
     channels,
	 channels_53,
     baudRates,
     parities,
     speeds,
     whileIfs,
     rs485Config,
	 comConfig,
	 timeoutOptions,
     ethernetConfig,
     loraConfig,
     zigbeeConfig,
     localConfig,
     modbusMaster,
     modbusClient,
     modbusSlave,
     localSlave,
     localSlave54,
     s7_200_ppi,
	 dl_T645,
     s7_1200_1500,
	 fx_serial_port,
	 famtterFxs,
	 checkFxs,
     cmds_16,
     orders_16,
     orders_32,
     orders_64,
     crc_modes,
     waterMarks,
     addSensor_modbus,
     addSensor_s7200,
     addSensor_1200_1500,
	 addSensor_mitsubishi_fx,
	//方法
	 versionToFloat,
     padLeft,
     createDataKey,
     defaultMinMax

 };
 //congfigData是V5远程配置共用数据的整体封装导出
 export default configData;
 //分开导出用于其他地方
 export {
     // configData,
	 numToTime,
     reportTypes,
     whileIfs,
     saves,
     oldOptions,
     oldPoints,
     steps,
     options,
	 optionsOnlyRead,
     points,
     valueTypes_IQ,
     valueTypes_MV,
     valueTypes_01,
     valueTypes_34,
	 valueTypes_T645,
	 valueTypes_Fx_D,
     padLeft,
     createDataKey,
	 versionToFloat
 };
